package com.hqyj.ssm_project.controller;

import com.hqyj.ssm_project.pojo.Function;
import com.hqyj.ssm_project.service.FunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class FunctionController {
    @Autowired
    private FunctionService functionService;
    @RequestMapping(value = "/functionPage.do")
    public String functionPage(Model model){
        List<Function> functionList=functionService.selectAllfunction();
        model.addAttribute("functionList",functionList);
        return "functionPage";
    }
    @RequestMapping("/addFunctionPage.do")
    public String addFunctionPage(){
        return "addFunctionPage";
    }
    @RequestMapping(value = "addFunction.do")
    public String addFunction(Function function){
        functionService.insert(function);
        return "redirect:functionPage.do";
    }
    @RequestMapping(value = "/updateFunctionPage.do")
    public String updateFunctionPage(Integer id,Model model){
        Function function = functionService.selectByPrimaryKey(id);
        model.addAttribute("function",function);
        return "updateFunctionPage";
    }
    @RequestMapping(value = "/updateFunction.do")
    public String updateFunction(Function function){
        functionService.updateByPrimaryKeySelective(function);
        return "redirect:functionPage.do";
    }
    @RequestMapping(value = "/deleteFunction.do")
    public String deleteFunction(Integer id){
        functionService.deleteByPrimaryKey(id);
        return "redirect:functionPage.do";
    }
}
